cmake_minimum_required(VERSION 3.4.1)
project(opencv_learn)

set(CMAKE_CXX_STANDARD 11)
set(VERSION_STRING 0.1.1)
set(SOVERSION_STRING 0.1.1)
include(cmake/platform.cmake)  # checking platform

message(STATUS "opencv_learn  ${VERSION_STRING}")
message(STATUS "Project: opencv_learn")
message(STATUS "Version: ${VERSION_STRING}")
message(STATUS "SO Version: ${SOVERSION_STRING}")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Platform Name: ${PLATFORM_NAME}")
message(STATUS "Root Path: ${CMAKE_SOURCE_DIR}")

# Linux GCC Compiler Options
if (CMAKE_COMPILER_IS_GNUCXX)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s -O3")
    set(CMAKE_CXX_FLAGS "-Wno-deprecated -s -O3 ${CMAKE_CXX_FLAGS} ")
    #set(CMAKE_CXX_FLAGS "-std=c++11 -Wno-deprecated -s -O3 ${CMAKE_CXX_FLAGS} ")
    #message(STATUS "[Linux GCC Compiler Options]+:-std=c++11 -Wno-deprecated")
endif ()
message(STATUS "CMAKE_CXX_COMPILER: [${CMAKE_CXX_COMPILER}]")

if("${CMAKE_BUILD_TYPE}" MATCHES "")
  set(CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "CMAKE_BUILD_TYPE: [${CMAKE_BUILD_TYPE}]")

# root dir
set(UR_Root ${CMAKE_SOURCE_DIR})
if (NOT DEFINED CMAKE_INSTALL_PREFIX)
    set(CMAKE_INSTALL_PREFIX ${UR_Root}/install)
endif ()

#build system plat
#option(USE_OPENCV_BASE "use base opencv" ON)

#message(STATUS "Engines Enable Details ... ")
#message(STATUS "USE_OPENCV_BASE: ${USE_OPENCV_BASE}")

include(cmake/opencv.cmake) #opencv

# set default build dir
if (NOT DEFINED RELEASE_DIR)
    set(RELEASE_DIR ${UR_Root}/build)
endif ()

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR})
    SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR})
    add_compile_options(-fPIC -Wall -Wno-unused-variable -Wno-unused-value)
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
    if (CMAKE_CL_64)
        set(CL_32_64 x64)
    else ()
        set(CL_32_64 x86)
    endif ()
    #SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/${CL_32_64}/${CMAKE_BUILD_TYPE})
    SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/${CL_32_64})
    SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/${CL_32_64})
endif ()
LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})

set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "[Compiler Options]+: ${CMAKE_CXX_FLAGS} ")
if (MSVC AND ENABLE_MSVC_MT)
    set(CompilerFlags
        CMAKE_CXX_FLAGS
        CMAKE_CXX_FLAGS_DEBUG
        CMAKE_CXX_FLAGS_RELEASE
        CMAKE_C_FLAGS
        CMAKE_C_FLAGS_DEBUG
        CMAKE_C_FLAGS_RELEASE
        )
    foreach(CompilerFlag ${CompilerFlags})
        string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
    endforeach()
endif()

#设置头文件目录
INCLUDE_DIRECTORIES(${UR_Root}/include)
INCLUDE_DIRECTORIES(${UR_Root}/src)

#收集源代码
file(GLOB opencv_src_list ${UR_Root}/src/*.h ${UR_Root}/src/*.cpp)

if (WIN32)
  #list(APPEND LINK_LIBS Iphlpapi shlwapi)
endif()

#安装目录
set(INSTALL_PATH_LIB ${CMAKE_INSTALL_PREFIX}/lib)
set(INSTALL_PATH_INCLUDE ${CMAKE_INSTALL_PREFIX}/include)
set(INSTALL_PATH_EXECUTABLE ${CMAKE_INSTALL_PREFIX}/bin)

add_executable(opencv_learn ${opencv_src_list})
target_link_libraries(opencv_learn ${LINK_LIBS})   

#安装
install(TARGETS opencv_learn DESTINATION ./)    
#execute_process(COMMAND cp ${RGA_API_LIB} ${EXECUTABLE_OUTPUT_PATH}/)
